Analyzing a
Simple Java* Application with VTune and Microsoft Visual J++*
This is a step-by-step process to show the highlights of using VTune with
a Java* application. The user is encouraged to
explore the VTune screens (ex: context sensitive help, display
options, etc.) while going through these instructions.
These instructions reflect working with Java programs using
Microsofts development environment. Instructions for using
other languages and environments will be placed on the following URL
as new support is defined:
http://developer.intel.com/design/perftool/vtune/prod_rev.htm
These instructions require that VTune 2.5, Microsoft Visual J++ 1.1, and Internet Explorer 4.0 are installed.
Create and Compile the XForm Java Application
1. Invoke Visual J++ with no active project
2. Click File->New, select Files->Text, click OK. A blank text window appears.
3. Type in the following program:
public class Xform
{
public static void scale (double [] x, double [] y, double s)
{
int i, j;
for (i=0; i < 3000; i++)
for (j=0; j<12000; j++)
y[i] += x[i] / s;
}
public static void main (String args[])
{
int i;
long startTime, endTime;
double dx[] = new double[3000];
double dy[] = new double[3000];
for (i=0; i<3000; i++) dy[i] = dx[i] = i;
startTime = System.currentTimeMillis();
scale (dx, dy, 0.5);
endTime = System.currentTimeMillis();
System.out.println ("Program completed.\n\n\n");
System.out.print ("Execution time in milliseconds:");
System.out.println (endTime-startTime);
try {Thread.currentThread().sleep (3000);}
catch (InterruptedException e) {}
}
}
4. Click File->SaveAs, type Xform.java as the filename. The name Xform must exactly match the Xform on the public
class statement above.
5. Click Build->Compile. A dialog box is generated asking to create a default workspace. Click Yes. The Xform application
is then built. By default, Debug is turned on. VTune requires debug information to display source code.
6. After it compiles correctly, click Build->Execute. A dialog box is generated asking about which class to run. Type Xform
as the class. Select the radio button for using a stand alone interpreter. Click Yes. The Xform application runs for several
seconds, and then ends.
Find Xforms Hotspot with VTune 2.5
1. Invoke VTune 2.5. If the VTune Assistant window appears, close it by unclicking the Show on Startup radio button and
click the red X. It can be re-invoked with View->Assistant.
2. Click File->NewProject. The NewProject wizard will ask some questions:
Program to test: jview.exe with path, probably c:\windows\jview.exe. Click Next.
Working directory: Directory from Create and Compile steps above. Click Next.
Command line parameters: Xform (Note the .class filename extension is not needed). Click Next.
Starting and ending keystrokes: Leave Blank. Click Next.
How long for application to run: 20 seconds. Click Next.
Source Code Dir: Dir from Create and Compile steps above. Click Next.
VTune Output Dir: Dir from Create and Compile steps above. Click Finish.
3. Click View->ProjectOptions->Click Advanced tab->Enable Java Call Graph Profiling, Click Automation tab, Click on Terminate
Program When Monitoring Session ends, Click Close
4. Click the Run->StartMonitorSession command. This runs the Xform program.
5. After several seconds when the jview xform window closes, if VTune is still sampling (Session starting... appears in VTune
main menu window) click the Run->EndMonitorSession command. The Sessions for jview window appears.
6. Double click Testing jview.exe. The modules report appears. Maximize the window. This shows a system wide view of
software modules executing in the system.
7. The modules are alphabetical from the top. Double click the Javaxxxx.jit line - This code was Jitd at run time. The HotSpot window appears.
8. Double click on the longest red line, which is the hotspot.
9. The analysis window appears with the hotspots source code displayed. Note the line of source with the biggest time
number to the left of the line. This is the source code for Xforms hotspot.
Get Advice on Speeding Up Xform
1. Double click on the hotspot source line: y[i] += x[i]/s; VTunes Java coach shows 2 pieces of advice:
(1) Compute the reciprocal of s outside the loop & do a multiply instead of divide in the
loop (Multiplies are faster than divides)
(2) y & x references can be pulled outside the j loop since they are independent of j
Click question marks next to advice for more detail.
Close Java coach window.
At this point you may want to make the suggested changes to the source code of Xform, recompile and see how much it is
improved.
2. Click the View->MixAssemblerAndSource command.
In this view VTune displays detailed information from the CPUs point of view as to how the Java program executes. Native
assembly language code for the Java program is displayed. This native code is annotated with detailed information about how
the processor executes these instructions. Included are Pentium® processor pairing information (color coded on the left),
Pentium processor clock cycle counts, performance penalties, and CPU usage percentages from the profiling done earlier.
Other data may be requested (Pentium II processor micro-ops, decoder groups, etc) using the
Options->ColumnDisplayOptions command.
3. VTune also gives instruction level advice. Double click the line that has the penalty FP_Dep_ST(0) on the right to learn
more about ways performance can be improved.
4. Close windows until youre back to the Sessions for jview window from the end of step 5.
Display the Xform Call Graph
1. Back in the Sessions for jview windows, double click on Java Call Graph in sessions window. Maximize the call graph
window
2. Left side of window: Calling info in spreadsheet format.
Right side: Calling info in graphical format.
3. Grab vertical separator bar between the 2 halves, move to right until spreadsheet time column appears. Other columns (ex:
number of callers & callees) may be seen farther right.
4. Click word time at top of spreadsheet column to sort methods by increasing time.
Click it again to sort by decreasing time. The Xform.scale method took the longest amount of time by far. Graph on right
shows Xform.main calling Xform.scale.
5. Double click on xform.main on the graph to see its callers and callees. Click Fit at the top menu bar, or move the middle
separator to left if needed. The caller and callees of the xform.main method are shown in graphical format. The blue line
indicates the critical path, the numbers represent the number of calls.
|